#include <iostream>
#include <string.h>
using namespace std;
//验证为什么要把析构函数也放到虚函数表里面
class A{
public:
    A(const char * p)
    :_pa(new char[strlen(p)+1])
    {
        strcpy(_pa,p);
    }
    virtual
    void print(){
        cout<<"A::print()"<<endl;
    }
    virtual
    ~A(){
        cout<<"~A"<<endl;
        if(_pa){
            delete[] _pa;
            _pa=nullptr;
        }
    }
    char* _pa;
};
class B:public A{
    public:
        B( const char* pa,const char * p)
        :A(pa)
         ,_p(new char[strlen(p)+1])
        {
            strcpy(_p,p);
        }
        ~B(){
            cout<<"~B"<<endl;
            if(_p){
                delete [] _p;
                _p=nullptr;
            }
        }    
    void print(){
        cout<<"B::print()"<<endl;
    }

    char *  _p;
};
void test(){
    A* a=new B("hello","world");
    a->print();
    delete a;
}
int main(int argc, char * argv[]){
    test();    
    return 0;
}

